<?php
namespace Api\Controller;
use Think\Controller;
class OrderController extends CommonController{

    //实例化用户
    protected $currentUser;
    
    function _initialize() {
        parent::_initialize();
        
        //判断token是否存在
        $token = I('post.token');

        $userMap['token'] = $token;
        $user = $this->userModel->where($userMap)->find();

        if(isNullOrEmpty($user)) {
            $this->errorReturn('ERROR_TOKEN');
        }

        $this->currentUser = $user;
        
    }

    //创建订单页
    public function createOrderIndex() {

        //判断师傅是否存在
        $masterId = I("post.masterId");

        $master = $this->userModel->queryById($masterId);

        if(isNullOrEmpty($master)) {
            $this->errorReturn("ERROR_MASTER_NOT_FOUND");
        }

        $basicInfo = $this->userModel->getMasterDetailInfo($this->currentUser["user_id"], $masterId);

        $this->returnData['data']['basic_info'] = $basicInfo;

        $this->response($this->returnData, 'json');

    }

    public function createOrder() {

        $result = $this->orderModel->createOrder($this->currentUser["user_id"]);

        if(!is_numeric($result)) {
            $this->errorReturn($result);
        }

        $this->returnData['data']['orderId'] = $result;

        $this->response($this->returnData, 'json');

    }

}